<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : receive.manage.php   FILE_PATH : D:\webroot\mulitishop\system\receive.manage.php
 * ....会员收货地址后台管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Wed Oct 24 17:14:03 CST 2007
 */

require_once("../global.inc.php");

class SysReceiveManage extends SystemFrameWork{
	/**
	 * 收货地址对象
	 *
	 * @var obj
	 */
	var $obj_receive;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;

	function main(){
		/**
		 * 创建文章对象
		 */
		if (!is_object($this->obj_receive)){
			require_once("receive.class.php");
			$this->obj_receive = new ReceiveClass();
		}
		/**
		 * 创建分页对象
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 语言包
		 */
		$this->getlang("article");

		switch($this->_input['action']){
			case "add":
				$this->_addReceive();
				break;
			case "addsave":
				$this->_addsaveReceive();
				break;
			case "del":
				$this->_deleReceive();
				break;
			case "modi":
				$this->_modiReceive();
				break;
			case "modisave":
				$this->_modisaveReceive();
				break;
			default:
				$this->_getReceive();
		}
	}

	/**
	 * 得到收货地址列表
	 *
	 */
	function _getReceive(){
		$this->obj_page->pagebarnum(20);    //每页20条记录
		$receive_array = $this->obj_receive->getAllReceive($this->_input,$this->obj_page);
		$pagelist = $this->obj_page->show(1);      //分页显示
		// print_r($receive_array);
		$this->output('receive_array',$receive_array);
		$this->output("pagelist", $pagelist);    //输出分页
		$this->showpage("sys_receive.manage");
	}

	/**
	 * 修改收货地址信息
	 *
	 */
	function _modiReceive(){
		$receive_array = $this->obj_receive->getOneReceive($this->_input['memberid'],$this->_input['receiveid']);
		//print_r($receive_array);
		$this->output('receive_array',$receive_array);
		$this->showpage("sys_receive.modi");
	}
	/**
	 * 修改收货地址信息
	 *
	 */
	function _modisaveReceive(){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtReceiveName"],"require"=>"true","message"=>"请填写接收人"),
		array("input"=>$this->_input["txtProvince"],"require"=>"true","message"=>"请选择寄送省市"),
		array("input"=>$this->_input["txtCity"],"require"=>"true","message"=>"请选择寄送市区"),
		array("input"=>$this->_input["txtAddress"],"require"=>"true","message"=>"请填写寄送地址"),
		);
		$error = $this->objvalidate->validate();
		if ($error != "" ){
			//echo $error;
			$this->redirectPath("error","",$error);
		}else{
			//$this->_input['member_id'] = $_SESSION['s_login']['id'];
			$exist = $this->obj_receive->isExistReceive($this->_input['receive_id'],'receive_id',$this->_input['member_id']);
			if ($exist == true){
				$this->obj_receive->modiReceive($this->_input);
				//$this->redirectPath("succ","/member/own_receive.php","您修改收货地址成功！");exit;
			}
			//$this->redirectPath("error","","收货地址不存在！".$exist);
		}
	}
	/**
	 * 删除收货地址
	 *
	 */
	function _deleReceive(){
		$this->obj_receive->delReceive($this->_input['receiveid'],$this->_input['memberid']);
		//$this->redirectPath("succ","/member/own_receive.php","您删除收货地址成功！");
	}

	function _addReceive(){
		$this->showpage("sys_receive.add");
	}
	/**
	 * 保存新增收货地址
	 *
	 */
	function _addsaveReceive(){

		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtMemberName"],"require"=>"true","message"=>"请填写帐号"),
		array("input"=>$this->_input["txtReceiveName"],"require"=>"true","message"=>"请填写接收人"),
		array("input"=>$this->_input["txtProvince"],"require"=>"true","message"=>"请选择寄送省市"),
		array("input"=>$this->_input["txtCity"],"require"=>"true","message"=>"请选择寄送市区"),
		array("input"=>$this->_input["txtAddress"],"require"=>"true","message"=>"请填写寄送地址"),
		);

		$error = $this->objvalidate->validate();
		if ($error != "" ){
			$this->redirectPath("error","",$error);
		}else{

			require_once("member.class.php");
			$obj_member = new Member();
			$member_id = $obj_member->checkMemberExist($this->_input['txtMemberName'],"login_name","","2");
			//echo $member_id;exit;
			if ($member_id != false){



				/**
			     * 获得随机的唯一编码
			     */
				$receive_last_id = $this->obj_receive->getReceiveLastId();
				if("" == $receive_last_id){
					$receive_last_id = 1;
				}else{
					$receive_last_id += 1;
				}
				$chars = array(
				"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
				"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
				"w", "x", "y", "z"
				);
				$random_string = Common::genRandomString($chars, 4);
				$this->_input["txtRcode"] = md5($receive_last_id.$random_string);

				$this->_input['member_id'] = $member_id;
				$this->obj_receive->addReceive($this->_input);
				$this->redirectPath("succ","/member/own_receive.php","您新增收货地址成功！");
			}
		}
	}
}

$receive_manage = new SysReceiveManage();
$receive_manage->main();
unset($receive_manage);
?>